package com.wlr.study.leetcode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * 对称二叉树
 * 输入：root = [1,2,2,3,4,4,3]
 * 输出：true
 *
 * @author lrwang
 * @version 1.0
 * @date 2022/4/6 20:35
 */
public class LeetCode101 {
    List<Integer> list = new ArrayList<>();
    List<Integer> list1 = new ArrayList<>();

    public boolean isSymmetric(TreeNode root) {
        return check(root.left, root.right);
    }

    public boolean check(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p == null || q == null) {
            return false;
        }
        return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);
    }

    public static void main(String[] args) {
        LeetCode101 leetcode101 = new LeetCode101();
        TreeNode root = new TreeNode(1);
        TreeNode rootL = new TreeNode(2);
        TreeNode rootR = new TreeNode(2);
        TreeNode rootLl = new TreeNode(2);
//        TreeNode rootLr = new TreeNode(4);
        TreeNode rootRl = new TreeNode(2);
//        TreeNode rootRr = new TreeNode(4);
        root.left = rootL;
        rootL.left = rootLl;
//        rootL.right = rootLr;
        rootR.left = rootRl;
//        rootR.right = rootRr;
        root.right = rootR;
        System.out.println(leetcode101.isSymmetric(root));
    }

}
